<?php
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'autoload.php';

use payClass\Datebase;
use payClass\QRcode;
use payClass\pay\Config;

/**
 * 出款
 */
class Payment
{
	public static function paymentDo()
	{
		$db     = new Datebase();

		$config = new Config();

		$param  = $db->param();
		$param = [
		    'order'          =>  time().uniqid(),
		    'amount'         =>  '100',
		    'account_Name'   =>  '赵忠意',
		    'account_Number' =>  '6217003380009745164',
		    'bank_Code'      =>  'HPT00003',
		    'bank_Name'      =>  '中国建设银行',
		];

		// 数据检测
		// $verifyRes = $db->verifyDraw($param);

		// if ($verifyRes != 1) exit($verifyRes);

		$dataArray = [
			'mchId'           => Config::$merchant,
			'appId'           => Config::$appid,
			'mchTransOrderNo' => $param['order'],
			'currency'        => 'cny',
			'amount'          => $param['amount'] * 100,
			'notifyUrl'       => Config::$paymentNotifyUrl,
			'bankCode'        => $param['bank_Code'],
			'bankName'        => $param['bank_Name'],
			'accountType'     => 1, // 1-银行卡转账,2-微信转账,3-支付宝转账,4-其他转账
			'accountName'     => $param['account_Name'],
			'accountNo'       => $param['account_Number'],
			'province'        => '北京',
			'city'            => '北京',
		];

		$dataArray['sign'] = Config::getSignMsg($dataArray);

		ksort($dataArray);

		$data['params']    = json_encode($dataArray);

		$curlRes           = Config::curl(Config::$api . '/api/trans/create_order', $data);

		$resArray          = json_decode($curlRes, true);
print_r($resArray);die;
		if ($resArray['code'] != '0') $db->ajaxReturn($resArray['msg']);

		$db->ajaxReturn($resArray['提交成功']);
	}
}

Payment::paymentDo();
